home *** CD-ROM | disk | FTP | other *** search
/ Unreal Tournament Game Programming for Teens / UnrealTournamentGameProgrammingForTeens.iso / Chapter Files / Chapter05 / Ch04Area / Classes / ScoreKeeper.uc < prev    next >
Encoding:
Text File  |  2006-10-23  |  3.1 KB  |  134 lines

  1. //=============================================================================
  2. // ScoreKeeper.
  3. //=============================================================================
  4. class ScoreKeeper extends Actor placeable;
  5.  
  6.    struct CodeStatus{
  7.       var string Letter;
  8.       var bool Found;
  9.       var int Times;
  10.    };
  11.    const CODELENGTH = 8;
  12.    const LOWASCII = 97;
  13.    const HIGHASCII = 122;
  14.    const NUMOFTRIES = 50;
  15.    var CodeStatus GoalsMet[CODELENGTH];
  16.    var string CodeForSearch;
  17.    var string FirstMessage;
  18.    var string Report;
  19.    var string PMessage;
  20.  
  21. /*
  22.    function int Main(string Args)
  23.    {
  24.  
  25.      log("*************");
  26.      log("Ch25_O3LIST");
  27.      log("*************");
  28.      //This goes in PostBeginPlay()
  29.      MakeCode();
  30.  
  31.      //This goes in MakeMessage for DOWN
  32.      RunCodeFinder();
  33.      PMessage = ReportFirstMessage();
  34.      Log(PMessage);
  35.  
  36.      return 0;
  37.    }
  38. */
  39.  
  40. //========= Interface of Code Class ================
  41.    function public RunCodeFinder(){
  42.      SetGoals();
  43.      DetectLetter();
  44.    }
  45.  
  46.  
  47.    function public string ReportFirstMessage(){
  48.       return CodeForSearch @ FirstMessage @ Report;
  49.    }
  50.  
  51.    function public MakeCode(){
  52.       local int Ctr;
  53.       while (Ctr < CODELENGTH){
  54.         CodeForSearch $= Chr(GenerateRandom());
  55.         Ctr++;
  56.       }
  57.    }
  58.  
  59. //===================================================
  60.  
  61.    function private string ShowCode(){
  62.        return CodeForSearch;
  63.    }
  64.  
  65.    function private int GenerateRandom(){
  66.       local float High, Low;
  67.       Low = LOWASCII;
  68.       High = HIGHASCII;
  69.       return Int(RandRange(Low, High));
  70.    }
  71.  
  72.    function private SetGoals(){
  73.       local int Ctr;
  74.       Ctr = 0;
  75.       while(Ctr < CODELENGTH){
  76.         GoalsMet[Ctr].Letter
  77.                    = Right( Left(CodeForSearch, Ctr+1), 1);
  78.         GoalsMet[Ctr].Found = false;
  79.         Ctr++;
  80.       }
  81.    }
  82.  
  83.    function private GetGoals(){
  84.       local int Ctr;
  85.       Report="";
  86.       while(Ctr < CODELENGTH){
  87.         //----
  88.         Report $= GoalsMet[Ctr].Letter $ GoalsMet[Ctr].Found
  89.                                        $ GoalsMet[Ctr].Times;
  90.         Ctr++;
  91.       }
  92.    }
  93.  
  94.    function private DetectLetter(){
  95.      local int Ctr, Itr, NumberOfFinds;
  96.  
  97.      Ctr =0;
  98.      while(Ctr < NUMOFTRIES){
  99.         Itr = 0;
  100.         while(Itr < CODELENGTH){
  101.            if( GoalsMet[Itr].Letter == Chr(GenerateRandom() ) ){
  102.               GoalsMet[Itr].Found = true;
  103.               GoalsMet[Itr].Times++;
  104.               NumberOfFinds++;
  105.            }//end if
  106.            Itr++;
  107.         }//end inner while
  108.         Ctr++;
  109.      }//end outer while
  110.      GetGoals();
  111.      CheckForWin();
  112.    }//end Detect
  113.  
  114.    function private CheckForWin(){
  115.       local int Itr, Goal;
  116.       Itr = 0;
  117.       Goal = 0;
  118.       while(Itr < CODELENGTH){
  119.         if(GoalsMet[Itr].Found == true){
  120.           Goal++;
  121.           if(Goal == CODELENGTH){
  122.             FirstMessage = "You found the whole code!";
  123.           }else{
  124.             FirstMessage = "Code is still incomplete!";
  125.           }//end inner if else
  126.         }//end outer if
  127.         Itr++;
  128.       }//end while
  129.    }//end Check
  130.  
  131. defaultproperties
  132. {
  133. }
  134.